package com.turnengine.client.local.unit.command;

import com.turnengine.client.local.unit.enums.UnitMove;
import com.turnengine.client.local.unit.enums.UnitNode;
import com.turnengine.client.local.unit.enums.UnitType;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Add Unit.
 */
public class AddUnit implements IAddUnit {

	/** The command id. */
	public static final short COMMAND_ID = 1901;

	/** The login id. */
	private long loginId;
	/** The instance id. */
	private int instanceId;
	/** The name. */
	private String name;
	/** The node. */
	private UnitNode node;
	/** The type. */
	private UnitType type;
	/** The move. */
	private UnitMove move;
	/** The group name. */
	private String groupName;
	/** The faction name. */
	private String factionName;

	/**
	 * Creates a new Add Unit.
	 */
	public AddUnit() {
	}

	/**
	 * Creates a new Add Unit.
	 * @param loginId the login id
	 * @param instanceId the instance id
	 * @param name the name
	 * @param node the node
	 * @param type the type
	 * @param move the move
	 * @param groupName the group name
	 * @param factionName the faction name
	 */
	public AddUnit(long loginId, int instanceId, String name, UnitNode node, UnitType type, UnitMove move, String groupName, String factionName) {
		setLoginId(loginId);
		setInstanceId(instanceId);
		setName(name);
		setNode(node);
		setType(type);
		setMove(move);
		setGroupName(groupName);
		setFactionName(factionName);
	}

	/**
	 * Creates a new Add Unit.
	 * @param iAddUnit the i add unit
	 */
	public AddUnit(IAddUnit iAddUnit) {
		setLoginId(iAddUnit.getLoginId());
		setInstanceId(iAddUnit.getInstanceId());
		setName(iAddUnit.getName());
		setNode(iAddUnit.getNode());
		setType(iAddUnit.getType());
		setMove(iAddUnit.getMove());
		setGroupName(iAddUnit.getGroupName());
		setFactionName(iAddUnit.getFactionName());
	}

	/**
	 * Returns the login id.
	 * @return the login id.
	 */
	public long getLoginId() {
		return loginId;
	}

	/**
	 * Returns the instance id.
	 * @return the instance id.
	 */
	public int getInstanceId() {
		return instanceId;
	}

	/**
	 * Returns the name.
	 * @return the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the node.
	 * @return the node.
	 */
	public UnitNode getNode() {
		return node;
	}

	/**
	 * Returns the type.
	 * @return the type.
	 */
	public UnitType getType() {
		return type;
	}

	/**
	 * Returns the move.
	 * @return the move.
	 */
	public UnitMove getMove() {
		return move;
	}

	/**
	 * Returns the group name.
	 * @return the group name.
	 */
	public String getGroupName() {
		return groupName;
	}

	/**
	 * Returns the faction name.
	 * @return the faction name.
	 */
	public String getFactionName() {
		return factionName;
	}

	/**
	 * Sets the login id.
	 * @param loginId the login id to set.
	 */
	public void setLoginId(long loginId) {
		this.loginId = loginId;
	}

	/**
	 * Sets the instance id.
	 * @param instanceId the instance id to set.
	 */
	public void setInstanceId(int instanceId) {
		this.instanceId = instanceId;
	}

	/**
	 * Sets the name.
	 * @param name the name to set.
	 */
	public void setName(String name) {
		if (name == null) {
			throw new NullPointerException("name");
		}
		this.name = name;
	}

	/**
	 * Sets the node.
	 * @param node the node to set.
	 */
	public void setNode(UnitNode node) {
		if (node == null) {
			throw new NullPointerException("node");
		}
		this.node = node;
	}

	/**
	 * Sets the type.
	 * @param type the type to set.
	 */
	public void setType(UnitType type) {
		if (type == null) {
			throw new NullPointerException("type");
		}
		this.type = type;
	}

	/**
	 * Sets the move.
	 * @param move the move to set.
	 */
	public void setMove(UnitMove move) {
		if (move == null) {
			throw new NullPointerException("move");
		}
		this.move = move;
	}

	/**
	 * Sets the group name.
	 * @param groupName the group name to set.
	 */
	public void setGroupName(String groupName) {
		if (groupName == null) {
			throw new NullPointerException("groupName");
		}
		this.groupName = groupName;
	}

	/**
	 * Sets the faction name.
	 * @param factionName the faction name to set.
	 */
	public void setFactionName(String factionName) {
		this.factionName = factionName;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(1151, 37);
		hash.append(loginId);
		hash.append(instanceId);
		hash.append(name);
		hash.append(node);
		hash.append(type);
		hash.append(move);
		hash.append(groupName);
		hash.append(factionName);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof AddUnit) {
			AddUnit compare = (AddUnit) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.loginId, compare.loginId);
			equals.append(this.instanceId, compare.instanceId);
			equals.append(this.name, compare.name);
			equals.append(this.node, compare.node);
			equals.append(this.type, compare.type);
			equals.append(this.move, compare.move);
			equals.append(this.groupName, compare.groupName);
			equals.append(this.factionName, compare.factionName);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IAddUnit compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.loginId, compare.getLoginId());
		builder.append(this.instanceId, compare.getInstanceId());
		builder.append(this.name, compare.getName());
		builder.append(this.node, compare.getNode());
		builder.append(this.type, compare.getType());
		builder.append(this.move, compare.getMove());
		builder.append(this.groupName, compare.getGroupName());
		builder.append(this.factionName, compare.getFactionName());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("loginId", loginId);
		string.append("instanceId", instanceId);
		if (name != null) {
			string.append("name", name);
		}
		if (node != null) {
			string.append("node", node);
		}
		if (type != null) {
			string.append("type", type);
		}
		if (move != null) {
			string.append("move", move);
		}
		if (groupName != null) {
			string.append("groupName", groupName);
		}
		if (factionName != null) {
			string.append("factionName", factionName);
		}
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
